﻿using System.Linq;
using System.Xml.Linq;
using unTroublemaker.Conditions;

namespace unTroublemaker.Parsing
{
    public class InvertConditionParser : ISpecificationParser
    {
        public ISpecificationItem Parse(XElement element, ISpecificationParser genericParser)
        {
            var children = element.Elements().ToArray();
            if(children.Length == 0)
                throw new ParseException(ElementName + " must have a condition as a child element");

            var items = children.Select(c => genericParser.Parse(c, genericParser));
            return new InvertCondition(items);
        }

        public string ElementName { get { return "not"; } }
    }
}
